from machine import Pin
from neopixel import NeoPixel 
import time 

pin = Pin(13,Pin.OUT)
np = NeoPixel(pin,84)

display_time = []
#number 列表包含每一个3*5的数字
number = [
			[0, 1, 2, 3, 4, 6, 10, 12, 13, 14, 15, 16], 
			[12, 13, 14, 15, 16], [0, 1, 2, 4, 6, 8, 10, 12, 14, 15, 16], [0, 2, 4, 6, 8, 10, 12, 13, 14, 15, 16], 
			[2, 3, 4, 8, 12, 13, 14, 15, 16], [0, 2, 3, 4, 6, 8, 10, 12, 13, 14, 16], [0, 1, 2, 3, 4, 6, 8, 10, 12, 13, 14, 16], 
			[4, 10, 12, 13, 14, 15, 16], [0, 1, 2, 3, 4, 6, 8, 10, 12, 13, 14, 15, 16], [0, 2, 3, 4, 6, 8, 10, 12, 13, 14, 15, 16]
		]


# 对每一个数字进行处理
def Nuit_Time(nuit_time=[],colour=()) :
	n_time = []
	for i in range(18):
		if i in nuit_time:
			n_time.append(colour)
		else:
			n_time.append((0,0,0))
	return n_time


#分别把时间的点阵和颜色添到WS2812的寄存器里面
def New_Time(up_hour=[],up_hour_colour=(),down_hour=[],down_hour_colour=(),semicolon_colour=(),up_minute=[],up_minute_colour=(),down_minute=[],down_minute_colour=()):
	n_time = Nuit_Time(up_hour,up_hour_colour)
	for i in range(18):
		display_time.append(n_time[i])
	n_time = Nuit_Time(down_hour,down_hour_colour)
	for i in range(18):
		display_time.append(n_time[i])
	for i in range(12):
		display_time.append((0,0,0))
	n_time = Nuit_Time(up_minute,up_minute_colour)
	for i in range(18):
		display_time.append(n_time[i])
	n_time = Nuit_Time(down_minute,down_hour_colour)
	for i in range(18):
		display_time.append(n_time[i])
	display_time[37] = semicolon_colour
	display_time[39] = semicolon_colour
	display_time[43] = semicolon_colour
	display_time[45] = semicolon_colour
	for i in range(84):
		np[i] = display_time[i]
	np.write()

#分号闪烁
def semicolon_twinkle (times=1,colour=(4,5,6)):
	while 1 :
		np[37] = colour
		np[39] = colour
		np[43] = colour
		np[45] = colour
		np.write()
		time.sleep(times)
		np[37] = (0,0,0)
		np[39] = (0,0,0)
		np[43] = (0,0,0)
		np[45] = (0,0,0)
		np.write()
		time.sleep(times)

def init_time():
	New_Time(number[0],(3,3,3),number[0],(3,3,3),(4,5,6),number[0],(3,3,3),number[0],(3,3,3))
	semicolon_twinkle()


